addEventListener

abstract fun addEventListener(eventType: EventType, listener: Observer<Event>, useCapture: Boolean)

Adds the given listener to the event target.

You can use one of the predefined event types provided by the EventType class as an eventType parameter or create it manually through the of, for example:

EventType.of("click");
When an event of the given eventType is dispatched, the on method will be invoked if one of the following statements is true:
  • the event is at the AT_TARGET phase
  • the method was invoked with the useCapture = true and the event is at the CAPTURING_PHASE phase
  • the method was invoked with the useCapture = false and the event is at the BUBBLING_PHASE phase
Please note, that if you add the same EventListener instance for the same event type twice with the different useCapture values, the EventListener#on(Object) method will be invoked twice in the AT_TARGET phase as the engine distinguishes these event listeners.

This method does nothing if it has been already invoked with the same parameters.

Parameters

eventType

the type of the event that the listener will listen to

listener

the event listener instance

useCapture

a flag indicating that events of the given eventType will be dispatched to the given listener before being dispatched to any other EventTarget beneath it in the DOM tree. Events that are bubbling upward through the tree will not trigger the listener

Throws

when the document this instance belongs to is closed